/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.hwr.nbaplan.shared.model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.hibernate.annotations.Where;


/**
 * @NamedQuery(name = "Modul.findByNameProfKurs", query = "SELECT m FROM Modul m WHERE m.name = :name AND m.prof = :prof AND m.fkurs= :kurs")
 * @author flo
 */
@Entity
@Table(name = "t_modul", catalog = "nbaplan", schema = "")
@SequenceGenerator(name = "my_id", sequenceName = "modul_seq", initialValue = 1, allocationSize = 1)
@NamedQueries({
    @NamedQuery(name = "Modul.findAll", query = "SELECT m FROM Modul m"),
    @NamedQuery(name = "Modul.findById", query = "SELECT m FROM Modul m WHERE m.id = :id"),
    @NamedQuery(name = "Modul.findByName", query = "SELECT m FROM Modul m WHERE m.name = :name"),
    @NamedQuery(name = "Modul.findByProf", query = "SELECT m FROM Modul m WHERE m.prof = :prof")})
public class Modul implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "my_id")
    //@GeneratedValue(strategy = GenerationType.AUTO)
    @Basic(optional = false)
    @Column(name = "ID", nullable = false)
    private Integer id;
    @Basic(optional = false)
    @Column(name = "name", nullable = false, length = 255)
    private String name;
    @Basic(optional = false)
    @Column(name = "prof", nullable = false, length = 255)
    private String prof;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "fModul")
    @Where(clause = "deleted=0 or deleted is null")
    private Collection<Vorlesung> vorlesungCollection;
    @JoinColumn(name = "f_kurs", referencedColumnName = "ID", nullable = false)
    @ManyToOne(optional = false)
    private Kurs fKurs;
    

    /**
     *
     */
    public Modul() {
    }

    /**
     *
     * @param id
     */
    public Modul(Integer id) {
        this.id = id;
    }

    /**
     *
     * @param id
     * @param name
     * @param prof
     */
    public Modul(Integer id, String name, String prof) {
        this.id = id;
        this.name = name;
        this.prof = prof;
    }

    private Modul(String name, String professor) {
        this.name = name;
        this.prof = professor;
    }

    /**
     *
     * @param name
     * @param professor
     * @param kurs
     */
    public Modul(String name, String professor, Kurs kurs) {
        this.name = name;
        this.prof = professor;
        this.fKurs = kurs;
    }

    /**
     *
     * @return
     */
    public Integer getId() {
        return id;
    }

    /**
     *
     * @param id
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     *
     * @return
     */
    public String getName() {
        return name;
    }

    /**
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     *
     * @return
     */
    public String getProf() {
        return prof;
    }

    /**
     *
     * @param prof
     */
    public void setProf(String prof) {
        this.prof = prof;
    }

    /**
     *
     * @return
     */
    public Collection<Vorlesung> getVorlesungCollection() {
        return vorlesungCollection;
    }

    /**
     *
     * @param vorlesungCollection
     */
    public void setVorlesungCollection(Collection<Vorlesung> vorlesungCollection) {
        this.vorlesungCollection = vorlesungCollection;
    }

    /**
     *
     * @return
     */
    public Kurs getFKurs() {
        return fKurs;
    }

    /**
     *
     * @param fKurs
     */
    public void setFKurs(Kurs fKurs) {
        this.fKurs = fKurs;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Modul)) {
            return false;
        }
        Modul other = (Modul) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

  

    @Override
    public String toString() {
        return "de.hwr.nbaplan.shared.model.Modul[id=" + id + "]";

    }

   

   
}
